﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XinYi.CrookedShowMode;

namespace XinYi.CrookedShow.BLL
{
    public class Produc_Spu_SpecService : BaseService<Produc_Spu_Spec>
    {
        /// <summary>
        /// 根据Id获取商品spu信息
        /// </summary>
        /// <param name="spuId"></param>
        /// <returns></returns>
        public ProductSpuView GetProductSpuView(int spuId)
        {
            using (CrookedShowEntities db = new CrookedShowEntities())
            {
                var result = from spu in db.Product_Spu
                             join b in db.Brand on spu.BrandId equals b.Id
                             join c1 in db.Category on spu.One_Category_Id.ToString() equals c1.Id.ToString()
                             join c2 in db.Category on spu.Two_Category_Id.ToString() equals c2.Id.ToString()
                             join c3 in db.Category on spu.Three_Category_Id.ToString() equals c3.Id.ToString()
                             select new ProductSpuView()
                             {
                                 Id = spu.Id,
                                 Code = spu.Code,
                                 Name = spu.Name,
                                 BrandId = spu.BrandId,
                                 BrandName = b.Name,
                                 //OneCategoryId = spu.One_Category_Id,
                                 OneCategoryName = c1.Name,
                                 TwoCategoryId = spu.Two_Category_Id,
                                 TwoCategoryName = c2.Name,
                                 ThreeCategoryId = spu.Three_Category_Id,
                                 ThreeCategoryName = c3.Name,
                                 PublishStatus = spu.Publish_Status,
                                 AuditStatus = spu.Audit_Status,
                                 Weight = spu.Weight,
                                 Descript = spu.Descript
                             };
                return result.ToList()[0];
            }
        }
    }
}
